function zhuce(ev, ok) {
        if($("#registerform").valid() === true) {
                ev.stopPropagation();
                ok = (typeof ok != 'undefined') ? ok : false;
                if (ok) return true;
                $.blockUI({ message: $('#question_zhuce'), css: { width: '400px',height:'100px',border:'10px solid #999999'} });
                return false;
        }
}

$(document).ready(function() {
	var validator = $("#registerform").validate({
		rules: {
			username: {
				required: true,
				maxlength: 12,
				remote: "/users/check_username"
			},
			create_password: {
				required: true,
				minlength: 6
			},
			password_confirm: {
				required: true,
				minlength: 6,
				equalTo: "#create_password"
			},
			email: {
				required: true,
				email: true,
				remote: "/users/check_email"
			},
			dateformat: "required",
			terms: "required"
		},
		messages: {
			username: {
				required: "取个好听的呢称吧亲!",
				minlength: jQuery.format("请输入最少 {0} 个字符"),
				maxlength: jQuery.format("请输入最多 {0} 个字符"),
				remote: jQuery.format("该昵称无效或已被人注册")
			},
			create_password: {
				required: "请输入密码",
				rangelength: jQuery.format("请输入最少 {0} 个字符")
			},
			password_confirm: {
				required: "请再次输入密码",
				minlength: jQuery.format("请输入最少 {0} 个字符"),
				equalTo: "请确认您输入的是相同的密码"
			},
			email: {
				required: "请输入有效Email地址",
				minlength: "请输入有效Email地址",
				remote: jQuery.format("该邮箱已经被人注册了")
			},
			dateformat: "Choose your preferred dateformat",
			terms: " "
		},
		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next().next() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.next() );
			else
				error.appendTo( element.parent().next() );
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});
 	$('#registerform').bind('submit', zhuce);
	$('#yes_zhuce').click(function() {
                $('#registerform').trigger('submit', [true]);
                $.blockUI({ message: "<div style=\"margin-left:50px;flaot:left;margin-top:15px;font-size:14px;color:#999999;\">处理中...请不要关闭该页面！</div>" , css:{height:'50px',width:'400px',border:'10px solid #999999'}});
        });

        $('#no_zhuce').click(function() {
                $.unblockUI();
                return false;
                });


});

